package com.woniu40.separate_music.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu40.separate_music.entity.Music;
import com.woniu40.separate_music.entity.Music;
import com.woniu40.separate_music.mapper.MusicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
public class MusicService {
    @Autowired
    MusicMapper musicMapper;


    public PageInfo<Music> findMusicByUid(Integer pagenum, Integer pagesize, Integer userid) {
        List<Music> music = musicMapper.selectMusicByUserid(userid);
        PageHelper.startPage(pagenum, pagesize);
        PageInfo<Music> musicPageInfo = new PageInfo<>(music);
        return musicPageInfo;
    }

    public PageInfo<Music>  findMusicByPage(Integer pageNum, Integer pageSize, String singer, Integer tid){
        PageHelper.startPage(pageNum,pageSize);
        List<Music> musicList = musicMapper.selectMusicBycons(singer, tid);
        return new PageInfo<>(musicList);
    }

    public int removeMusic(Integer musicid){
        musicMapper.deleteCol(musicid);
        int i = musicMapper.deleteMusic(musicid);
        return i;
    }

    public int addMusic(Music music){
        int i = musicMapper.insertMusic(music);
        return i;
    }

    @Transactional
    public int cancelCol(Integer userid,Integer mid){
        musicMapper.deleteCollect(userid, mid);
        musicMapper.updateCount(mid);
        return 200;
    }
}
